<%@ page contentType="text/html; charset=utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>  

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title>展览管理</title>
    <c:set var="contextPath" value="${pageContext.request.contextPath}" scope="request"/>
	<link rel="stylesheet" href="${contextPath}/static-resources/css/index.css"/>
	<script src="${contextPath}/static-resources/jquery-1.12.1.js"></script>
	<script src="${contextPath}/static-resources/js/index.js"></script>
	
	<link rel="stylesheet" type="text/css" href="${contextPath}/static-resources/themes/material/easyui.css">
	<link rel="stylesheet" type="text/css" href="${contextPath}/static-resources/themes/icon.css">
	<script type="text/javascript" src="${contextPath}/static-resources/jquery.min.js"></script>
	<script type="text/javascript" src="${contextPath}/static-resources/jquery.easyui.min.js"></script>
	<script type="text/javascript">
		$(function(){
			$('#hallTable').datagrid({
				onDblClickRow: function(index,row){
					console.log(row.logo);
				}
			});
		})
		
		function authorFormatter(value){
			if (!value) {
				return "";
			}
			return value.name;
		}
		function exhibitionFormatter(value){
			if (!value) {
				return "";
			}
			return value.name;
		}
		function homeFormatter(value){
			if (!value) {
				return "";
			}
			return value.hall.name + ' * ' + value.name;
		}
		
		function openAddProductionWin(){
			$('#addProductionWin').window('open');
			$('#author').combobox('reload');
			$('#homeCombotree').combotree('reload');
			$('#exhibition').combobox('reload');
		}
		
		function hallFieldFormatter(value){
			if (!value) {
				return "";
			}
			return value.name;
		}

		function addProduction() {
			var name = $('#productionName').textbox('getValue');
			console.log(name);
			var flag = $('#productionFlag').textbox('getValue');
			console.log(flag);
			var authorId = $('#author').combobox('getValue');
			console.log(authorId);
			var homeId = $('#homeCombotree').combotree('getValue');
			console.log(homeId);
			var exhibitionId = $('#exhibition').combobox('getValue');
			if (!name) {
				showInfo("展厅名称不能为空");
				return;
			}
			if (!authorId) {
				showInfo("作者不能为空");
				return;
			}
			if (!homeId) {
				showInfo("所在展厅不能为空");
				return;
			}
			if (!exhibitionId) {
				showInfo("所属展览不能为空");
				return;
			}
			
			openMask();
			$.ajax({
				type : "POST",
				url : '${contextPath}/production/add.do',
				data : {"name" : name, "authorId" : authorId, "homeId" : homeId, "exhibitionId" : exhibitionId, "flag" : flag},
				success : function(data) {
					if (data.status) {
						$('#addProductionWin').window('close');
						$('#productionTable').datagrid('reload');
					} else {
						showError(data.message);
					}
					closeMask();
				},
				error : function() {
					showError('系统异常');
					closeMask();
				}
			});
		}
		
	</script>
</head>
<body style="height: 100%;">
	<div class="find_nav">
	    <div class="find_nav_left">
	        <div class="find_nav_list">
	            <ul>
	                <li><a href="javascript:void(0)" url="${contextPath}/exhibition/index.do">展览</a></li>
	                <li><a href="javascript:void(0)" url="${contextPath}/exhibitionHome/index.do">展厅</a></li>
	                <li class="selected"><a href="javascript:void(0)" url="${contextPath}/production/index.do">作品</a></li>
	                <li><a href="javascript:void(0)" url="${contextPath}/image/index.do">图片</a></li>
  	                <li><a href="javascript:void(0)" url="${contextPath}/user/index.do">用户</a></li>
  	                <li><a href="javascript:void(0)" url="${contextPath}/banner/index.do">banner</a></li>
	                <li class="sideline"></li>
	            </ul>
	        </div>
	    </div>
	</div>
	<div id="content" style="width: 100%; position: absolute;top: 45px;">
		<table id="productionTable" class="easyui-datagrid" title="作品" style="width:100%;height:100%;"
			data-options="rownumbers:true, singleSelect:true, url:'${contextPath}/production/listJson.do', method:'get',
			toolbar:'#productionTableTB' " >
			<thead>
				<tr>
					<th data-options="field:'ck', checkbox:true"></th>
					<th data-options="field:'name', width:'15%'">作品名称</th>
					<th data-options="field:'author', width:'15%'" formatter ="authorFormatter" >作者</th>
					<th data-options="field:'exhibition', width:'15%'" formatter ="exhibitionFormatter">所属展览</th>
					<th data-options="field:'home', width:'20%'" formatter ="homeFormatter">所在展厅</th>
					<th data-options="field:'createTime', width:'10%'" formatter ="dateTimeFormatter">创建时间</th>
					<th data-options="field:'flag', width:'15%'">标签</th>
					<th data-options="field:'imageSum', width:'5%'">图片数量</th>
				</tr>
			</thead>
		</table>
		
		<div id="productionTableTB">
			<a href="#" class="easyui-linkbutton" iconCls="icon-sum" plain="true" onclick="$('#productionTable').datagrid('reload')">查询所有</a>
         	<span class="datagrid-btn-separator" style="vertical-align: middle;display:inline-block;float:none"></span>
			<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="openAddProductionWin()">添加</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="">编辑</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="removeHall()">删除</a>
		</div>
		
		<!-- ##############下面是添加作品相关的窗体############## -->
		<div id="addProductionWin" class="easyui-window" title="添加作品" data-options="iconCls:'icon-add', collapsible:'false', modal:'true', closed:true, footer:'#addProductionWinFooter'" style="width:450px; height:350px; padding:10px;" >
			<div style="margin-bottom:5px">
				<input class="easyui-textbox" id="productionName" data-options="label: '名称：', labelPosition:'before'" style="width: 100%;"/>
			</div>
			<div style="margin-bottom:5px">
				<input class="easyui-combobox" id="author" name="author" style="width:100%" data-options="url: '${contextPath}/user/userList.do',
					method: 'get', valueField: 'id', textField: 'name', panelWidth: 350, panelHeight: 'auto', 
					labelWidth: '%', label: '作者：', labelPosition: 'before' ">
			</div>
			<div style="margin-bottom:5px">
				<select class="easyui-combotree" id="homeCombotree" style="width:100%;" data-options="label: '所在展厅：', labelPosition:'before', url:'${contextPath}/exhibitionHall/treeJson.do',method:'get' "></select>
			</div>
			<div style="margin-bottom:5px">
				<input class="easyui-combobox" id="exhibition"  data-options="label: '所属展览：', labelPosition:'before', url:'${contextPath}/exhibition/listJson.do',method:'get', valueField:'id', textField:'name'" style="width: 100%;"/>
			</div>
			<div style="margin-bottom:5px">
				<input class="easyui-textbox" id="productionFlag" data-options="label: '标签：', labelPosition:'before'" style="width: 100%;"/>
			</div>
		</div>
		
		<div id="addProductionWinFooter" class="windowFooter">
			<a href="#" class="easyui-linkbutton" icon="icon-ok" onclick="addProduction()">确定</a>  
            <a href="#" class="easyui-linkbutton" icon="icon-cancel" onclick="$('#addProductionWin').window('close')">取消</a>  
		</div>
		
	</div>
</body>


</html>